
module.exports = function ($scope, $state, $stateParams,$resource,$modal,FileUploader, toaster) {
    $scope.company_id = $stateParams.company_id;
    // $scope.getCompanyInfos = function () {
    //   $resource('/api/ac/ggc/reviewCompanyService/getApplyCompanyInfo', {}, {}).save({}, function(res){
    //       if(res.errcode != 0){ 
    //           toaster.error({title:"",body:res.errmsg});
    //           return;
    //       }
    //       console.log('查询企业信息是否完整');
    //       console.log(res);
    //       if (res.data.msg == '0') {
    //           alert('请先完善企业信息');
    //       } else if (res.data.msg == '1') {
    //           $scope.flag = '1'; // 信息完整
    //       }
    //   });
    // }
    // $scope.getCompanyInfos();
    $scope.getCompanyInfo = function(){
        $resource('/api/as/ggc/reviewCompany/findInfo', {}, {}).save({'company_id':$scope.company_id}, function(res){
            if(res.errcode === 0){  
                $scope.a = res.data;
                $scope.array = $scope.a.organization_img.split(',');
            }else{
                toaster.error({title:"",body:res.errmsg});
            }
        });
    }
    $scope.getCompanyInfo();
    $scope.employee={};
    
    $scope.ctarr=[
        {name:'王者单位',value:'0'},
        {name:'大师单位',value:'1'},
        {name:'钻石单位',value:'2'},
    ]
    $scope.submit = function(){
        if($scope.a.company_name==undefined||$scope.a.company_name==''){
            alert('请填写单位名称');
            return;
        }
        console.log($scope.a);
        $resource('/api/ac/ggc/reviewCompanyService/createCompany', {}, {}).save($scope.a, function(res){
            if(res.errcode === 0){ 
                toaster.success({title:"",body:'保存成功'});
                // $state.go('app.project_list',{});
            }else{
                toaster.error({title:"",body:res.errmsg});
            }
        });
    }

    //正则判断电话号  
    $scope.checkphone=function(x){
        if(!/^1[34578]\d{9}$/.test(x)) return "您输入的电话号长度或格式错误";
    }
    $scope.showphoneinfo=function(x){
        console.log(x);
        if(x==undefined){
            $scope.employee.phoneinfo="";
            return;
        }
        if(x==''){
            $scope.employee.phoneinfo="";
            return;
        }
                                  
        if($scope.checkphone(x)=="您输入的电话号长度或格式错误"){                
            $scope.employee.phoneinfo="您输入的电话号长度或格式错误"
        }else{
          $scope.employee.phoneinfo="";
        }
    }
    // 添加图片
    $scope.image = function(){
				var para = $state.get('app.imageupload');
				//设置上传文件夹，以自己业务命名
				angular.extend(para, {
					resolve : {  
						'dir' : function(){
							return 't1';
						}
					} 
				})
				var modalInstance = $modal.open(para);
				modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
					console.log('modal is opened');  
				});  
				modalInstance.result.then(function(result) {  
					$scope.array = result;
          $scope.a.organization_img=$scope.array.join(',');
				}, function(reason) {  
					console.log(reason);// 点击空白区域，总会输出backdrop  
					// click，点击取消，则会暑促cancel  
					$log.info('Modal dismissed at: ' + new Date());  
				}); 
		};    
    $scope.del=function(index){
        $scope.array.splice(index,1);
        $scope.a.organization_img=$scope.array.join(',');
    }
    // $scope.return=function(){
    //     $state.go('app.project_list',{});
    // }

};
